package com.agmte.api.common.utils;

import com.agmte.api.common.crud.utils.NamingCaseUtils;

/**
 * ClassName: UrlUtil
 * Description:
 *
 * @author YT
 * @date 2025/8/28 10:56
 */
public class UrlUtil {

    public static String join(String baseUrl, String... args) {

        for (String arg : args) {
            if (baseUrl.endsWith("/")) {
                baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
            }
            if (arg.startsWith("/")) {
                baseUrl += arg;
            } else {
                baseUrl = baseUrl + "/" + arg;
            }
        }
        return baseUrl;
    }

    public static String format(String url) {
        if (url.endsWith("/")) {
            url = url.substring(0, url.length() - 1);
        }
        if (!url.startsWith("/")) {
            url = "/" + url;
        }
        return url;
    }

    public static String urlToCamel(String baseUrl) {
        return NamingCaseUtils.snakeToCamel(baseUrl.replace("/", "_"));
    }
}
